/*
 * Activiti Modeler component part of the Activiti project
 * Copyright 2005-2014 Alfresco Software, Ltd. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * Urgentnotice
 */
var KisBpmUrgentnoticeCtrl = ['$scope', '$modal', function ($scope, $modal) {

    // Config for the modal window
    var opts = {
        template: 'editor-app/configuration/properties/urgentnotice-popup-template.html?version=' + Date.now(),
        scope: $scope
    };

    // Open the dialog
    $modal(opts);
}];

var KisBpmUrgentnoticePopupCtrl = ['$scope', '$http', function ($scope, $http) {

    if ($scope.property.value !== undefined && $scope.property.value !== null
        && $scope.property.value.urgentnotice !== undefined
        && $scope.property.value.urgentnotice !== null) {
        $scope.urgentnotice = $scope.property.value.urgentnotice;
    } else {
        $scope.urgentnotice = {};
    }

    $scope.popup = {
        urgentnotice: {
            emailTemplate :""
        }
    };

    $scope.isShow = true;

    $scope.emailTemplate = ""

    // 短信和邮箱
    $scope.isTextMessageChecked = false;
    $scope.isEmailChecked = false;

    if($scope.urgentnotice.isTextMessageChecked){
        $scope.isTextMessageChecked = $scope.urgentnotice.isTextMessageChecked
    }

    if($scope.urgentnotice.isEmailChecked){
        $scope.isEmailChecked = $scope.urgentnotice.isEmailChecked
    }

    if($scope.urgentnotice.emailTemplate){
        $scope.emailTemplate = $scope.urgentnotice.emailTemplate
    }

    $scope.emailOption = [
        {
            label: "email-template",
            value: "email-template"
        },
    ];


    $scope.emailChange = function (data) {
        console.log("data",data)
        $scope.popup.urgentnotice.emailTemplate = data;
        $scope.emailTemplate = data;
    };

    $scope.save = function () {
        $scope.urgentnotice.isTextMessageChecked = $scope.isTextMessageChecked;
        $scope.urgentnotice.isEmailChecked = $scope.isEmailChecked;
        $scope.urgentnotice.emailTemplate = $scope.isEmailChecked ? $scope.emailTemplate : null;
        $scope.property.value = {};
        $scope.property.value.urgentnotice = $scope.urgentnotice
        $scope.updatePropertyInModel($scope.property);
        $scope.close();
    };

    // Close button handler
    $scope.close = function () {
        $scope.property.mode = 'read';
        $scope.$hide();
    };

    console.log("$scope",$scope)

}];

